﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLNS.Models
{
    public class DienBienLuongModels
    {
        private static ITAPMNS2013Entities context = new ITAPMNS2013Entities();

        public static void Add(tblDienBienLuong dbl)
        {
            context.tblDienBienLuongs.AddObject(dbl);
            context.SaveChanges();
        }

        public static void Update(tblDienBienLuong dbl)
        {
            var query = from dienbienluong in context.tblDienBienLuongs
                        where dienbienluong.ID == dbl.ID
                        select dienbienluong;
            tblDienBienLuong kq = query.First<tblDienBienLuong>();
            kq = dbl;
            context.tblDienBienLuongs.ApplyCurrentValues(kq);
            context.SaveChanges();
        }

        public static void Delete(tblDienBienLuong dbl)
        {
            var query = (from dienbienluong in context.tblDienBienLuongs
                        where dienbienluong.ID == dbl.ID
                        select dienbienluong).FirstOrDefault();
            context.tblDienBienLuongs.DeleteObject(query);
            context.SaveChanges();
        }

        public static tblDienBienLuong GetThongTinCanBo(int id)
        {
           ITAPMNS2013Entities context11 = new ITAPMNS2013Entities();
            var query = (from dbl in context11.tblDienBienLuongs
                         orderby dbl.TuNgay descending
                         where dbl.IDCanBo == id
                         select dbl);
            return query.First<tblDienBienLuong>();
        }

        public static tblDienBienLuong GetDienBienLuongTheoNgay(int id,DateTime tungay)
        {
            ITAPMNS2013Entities context22 = new ITAPMNS2013Entities();
            var query = (from dbl in context22.tblDienBienLuongs
                        orderby dbl.TuNgay descending
                        where dbl.IDCanBo == id && dbl.TuNgay == tungay
                        select dbl);
            return query.First<tblDienBienLuong>();
        }
    }
}